﻿using PhilipService.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TCommon.Util;

namespace PhilipService
{
    public class RestServiceManager
    {
        private const string Url = "https://www.1meeting.cn/philips/";

        public LoginResponse Login(string name, string pwd) {
            var request = new LoginRequest()
            {
                Name = name,
                Password = pwd
            };

            var request_url = Url + "customerlogin";

            var response = (LoginResponse)HttpUtil.SendRequest<LoginRequest>(request_url,
                request, typeof(LoginResponse));

            return response;
        }

        public int SetStatus(long userid, int status) {
            var request = new SetStatusRequest()
            {
                CustomerId = userid,
                Status  = status
            };

            var request_url = Url + "changestatus";

            var response = (SetStatusResponse)HttpUtil.SendRequest<SetStatusRequest>(request_url,
                request, typeof(SetStatusResponse));

            return response == null ? 0 : response.Code;
        }

        public GetMyInfoResponse GetMyInfo(long customerId) {
            var request = new GetMyInfoRequest()
            {
                CustomerId = customerId,
            };

            var request_url = Url + "customercenter";

            var response = (GetMyInfoResponse)HttpUtil.SendRequest<GetMyInfoRequest>(request_url,
                request, typeof(GetMyInfoResponse));

            return response;
        }

        public GetUserInfoResponse GetUserInfo(string userid, long serviceId) {
            var request = new GetUserInfoRequest()
            {
                UserId = userid,
                ServiceId = serviceId
            };

            var request_url = Url + "lookuser";

            var response = (GetUserInfoResponse)HttpUtil.SendRequest<GetUserInfoRequest>(request_url,
                request, typeof(GetUserInfoResponse));

            return response;
        }

        public int EndService(long serviceId) {
            var request = new EndServiceRequest()
            {
                ServiceId = serviceId
            };

            var request_url = Url + "acceptservice";

            var response = (EndServiceResponse)HttpUtil.SendRequest<EndServiceRequest>(request_url,
                request, typeof(EndServiceResponse));

            return response == null ? 0 : response.Code;
        }

        public int AddOrUpdateServiceNote(long serviceId, string note) {
            var request = new AddNoteRequest()
            {
                ServiceId = serviceId,
                Note = note
            };

            var request_url = Url + "customernote";
            var response = (AddNoteResponse)HttpUtil.SendRequest<AddNoteRequest>(request_url,
                request, typeof(AddNoteResponse));
            return response == null ? 0 : response.Code; ;
        }

        public List<ServiceItem> GetServiceRecords(long customerId) {
            var request = new GetServiceRecordRequest()
            {
                CustomerId = customerId
            };

            var request_url = Url + "ownservicelist";

            var response = (List<ServiceItem>)HttpUtil.SendRequest<GetServiceRecordRequest>(request_url,
                request, typeof(List<ServiceItem>));

            return response;
        }

        public GetServiceDetailResponse GetServiceDetail(long serviceId) {
            var request = new GetServiceDetailRequest()
            {
                ServiceId = serviceId
            };

            var request_url = Url + "servicedetail";

            var response = (GetServiceDetailResponse)HttpUtil.SendRequest<GetServiceDetailRequest>(request_url,
                request, typeof(GetServiceDetailResponse));

            return response;
        }

        public GetDeviceInfoResponse GetDeviceInfo(string deviceId, long serviceId) {
            var request = new GetDeviceInfoRequest()
            {
                DeviceId = deviceId,
                ServiceId = serviceId
            };

            var request_url = Url + "lookdevice";

            var response = (GetDeviceInfoResponse)HttpUtil.SendRequest<GetDeviceInfoRequest>(request_url,
                request, typeof(GetDeviceInfoResponse));

            return response;
        }

        public int RefuseService(long customerId) {
            var request = new RefuseServiceRequest
            {
                CustomerId = customerId
            };

            var request_url = Url + "refuseservice";

            var response = (RefuseServiceResponse)HttpUtil.SendRequest<RefuseServiceRequest>(request_url,
                request, typeof(RefuseServiceResponse));

            return response == null ? 0 : response.Code;
        }

        public int CloseService(long serviceId) {
            var request = new CloseServiceRequest()
            {
                ServiceId = serviceId
            };

            var request_url = Url + "closeservice";

            var response = (CloseServiceResponse)HttpUtil.SendRequest<CloseServiceRequest>(request_url,
                request, typeof(CloseServiceResponse));

            return response == null ? 0 : response.Code;
        }
    }
}
